#pragma once
#include "Base.h"
#include "Thread.h"
#include "ServerPlayer.h"
#include "BaseProtocol.h"

class CServerPlayerManager : public CThread
{
public:
	CServerPlayerManager(void);
	~CServerPlayerManager(void);
	virtual void Run();
	virtual CServerPlayer* CreateServerPlayer(int nOrigin, int nServerId);

	BOOL BroadcastMsg(Msg *pMsg, int nOrigin);

	void AddServerPlayer(CServerPlayer *pPlayer);
	void RemoveServerPlayer(CServerPlayer *pPlayer);
	
	CServerPlayer* FindServerPlayer(int nOrigin, int nServerId);
	BOOL SendMsgToOrigin(Msg *pMsg, int nOrigin);

	CServerPlayer* FindLobbyPlayerByUserId(DWORD dwUserId);
protected:
	CObjPtrList<CServerPlayer> m_listServerPlayer[Max_Origin_Count];
	int m_nMaxOrigin;
	CLock m_lock;
};

extern CServerPlayerManager *g_pServerPlayerManager;